package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/shop/type")
public class TypeController {
    @Autowired
    TbTypeService tbTypeService;

    /**
     * 分类列表
     *
     * @return
     */
    @PostMapping("/getTypeTreeList")
    public Result getTypeTreeList() {
        return tbTypeService.getTypeTreeList();
    }

    /**
     * 选择下拉框
     *
     * @return
     */
    @PostMapping("/getSelectTypeTreeList")
    public Result getSelectTypeTreeList() {
        return tbTypeService.getSelectTypeTreeList();
    }

    /**
     * 新增
     *
     * @param tbType
     * @return
     */
    @PostMapping("/addType")
    public Result addType(@RequestBody @Validated TbType tbType) {
        return tbTypeService.addType(tbType);
    }

    /**
     * 图片上传
     *
     * @param file
     * @return
     */
    @PostMapping("/uploadTypeImage")
    public Result uploadTypeImage(@RequestPart("file") MultipartFile file) {
        return tbTypeService.uploadTypeImage(file);
    }

    /**
     * 编辑
     *
     * @param tbType
     * @return
     */
    @PostMapping("/updateType")
    public Result updateType(@RequestBody TbType tbType) {
        return tbTypeService.updateType(tbType);
    }

    /**
     * 删除
     *
     * @param typeId
     * @return
     */
    @PostMapping("/deleteType/{typeId}")
    public Result deleteType(@PathVariable("typeId") Integer typeId) {
        return tbTypeService.deleteType(typeId);
    }
}
